const { Random } = require('mockjs')
import redisDb from './redisconf'
export const toToken = async info => {
  let isHave = true
  let token
  while(isHave){
    token = Random.string(32)
    isHave = await redisDb.isHave(1,token)
    console.log({isHave,token})
  }
  console.log({isHave,token})
  await redisDb.set(1,token,info)
  console.log("token添加成功")
  return token
}

export const tokenTo = async token => {
  return await redisDb.get(1,token)
}

export const changeToken = async token => {
  const info = await redisDb.get(1,token)
  let isHave = true
  let n_token
  while(isHave){
    n_token = Random.string(32)
    isHave = await redisDb.isHave(1,n_token)
  }
  return n_token
}